//
//  CommentController.m
//  SmileWeather
//
//  Created by lanou3g on 15/10/5.
//  Copyright (c) 2015年 Èô∂Â§©Êµ∑. All rights reserved.
//

#import "CommentController.h"

@interface CommentController ()<UIWebViewDelegate>
{ UIWebView*webView;
    UIActivityIndicatorView *activityIndicatorView;
    UIAlertView *alert;
    
}
@end

@implementation CommentController

- (void)viewDidLoad {
    [super viewDidLoad];
    
        CGRect bounds = [[UIScreen mainScreen]applicationFrame];
        webView = [[UIWebView alloc]initWithFrame:bounds];
        webView.scalesPageToFit = YES;//自动对页面进行缩放以适应屏幕
        // webView.detectsPhoneNumbers = YES;//自动检测网页上的电话号码，单击可以拨打
        [self.view addSubview:webView];
        NSURL* url = [NSURL URLWithString:@"http://www.apple.com/cn/osx/"];//创建URL
        NSURLRequest* request = [NSURLRequest requestWithURL:url];//创建NSURLRequest
        [webView loadRequest:request];//加载
        webView.delegate = self;
        alert = [[UIAlertView alloc] initWithTitle:@"载入中..." message:@"请稍等片刻..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        
        
        activityIndicatorView = [[UIActivityIndicatorView alloc]
                                 initWithFrame : CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)] ;
        [activityIndicatorView setCenter: self.view.center] ;
        [activityIndicatorView setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleGray] ;
        [alert addSubview : activityIndicatorView] ;
        [alert show];
        

    // Do any additional setup after loading the view.
}


- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    UIAlertView *alterview = [[UIAlertView alloc] initWithTitle:@"加载失败,请重试" message:[error localizedDescription]  delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [alterview show];
     [activityIndicatorView stopAnimating];
    [alert dismissWithClickedButtonIndex:0 animated:YES];

}

-(void)webViewDidStartLoad:(UIWebView*)webView //当网页视图已经开始加载一个请求后，得到通知。
{
    [activityIndicatorView startAnimating] ;
}
-(void)webViewDidFinishLoad:(UIWebView*)webView //当网页视图结束加载一个请求之后，得到通知

{  [activityIndicatorView stopAnimating];
    [alert dismissWithClickedButtonIndex:0 animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
